import { IPanelTabPanel } from '@ibiz/model-core';
import { PanelContainerController } from '@ibiz-template/runtime';
import { PanelBottomTabPanelState } from './panel-bottom-tab-panel.state';

/**
 * @description 面板底部分页部件控制器
 * @export
 * @class PanelBottomTabPanelController
 * @extends {PanelContainerController<IPanelTabPanel>}
 */
export class PanelBottomTabPanelController extends PanelContainerController<IPanelTabPanel> {
  declare state: PanelBottomTabPanelState;

  /**
   * @description 新建状态
   * @protected
   * @returns {*}  {PanelBottomTabPanelState}
   * @memberof PanelBottomTabPanelController
   */
  protected createState(): PanelBottomTabPanelState {
    return new PanelBottomTabPanelState(this.parent?.state);
  }

  /**
   * @description 初始化
   * @returns {*}  {Promise<void>}
   * @memberof PanelBottomTabPanelController
   */
  async onInit(): Promise<void> {
    await super.onInit();
    this.state.activeTab = this.model.panelTabPages?.[0].id || '';
  }

  /**
   * @description 分页点击切换处理
   * @param {string} tabId
   * @memberof PanelBottomTabPanelController
   */
  onTabChange(tabId: string): void {
    this.state.activeTab = tabId;
  }
}
